home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / remtask.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  126 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: remtask.c,v 1.5 1996/08/16 14:05:12 digulla Exp $
  4.     $Log: remtask.c,v $
  5.     Revision 1.5  1996/08/16 14:05:12  digulla
  6.     Added debug output
  7.  
  8.     Revision 1.4  1996/08/13 13:56:07  digulla
  9.     Replaced __AROS_LA by __AROS_LHA
  10.     Replaced some __AROS_LH*I by __AROS_LH*
  11.     Sorted and added includes
  12.  
  13.     Revision 1.3  1996/08/01 17:41:18  digulla
  14.     Added standard header for all files
  15.  
  16.     Desc:
  17.     Lang: english
  18. */
  19. #include <exec/execbase.h>
  20. #include <exec/tasks.h>
  21. #include <aros/libcall.h>
  22.  
  23. #include "exec_debug.h"
  24. #ifndef DEBUG_RemTask
  25. #   define DEBUG_RemTask 0
  26. #endif
  27. #if DEBUG_RemTask
  28. #   undef DEBUG
  29. #   define DEBUG 1
  30. #endif
  31. #include <aros/debug.h>
  32.  
  33. /*****************************************************************************
  34.  
  35.     NAME */
  36.     #include <clib/exec_protos.h>
  37.  
  38.     __AROS_LH1(void, RemTask,
  39.  
  40. /*  SYNOPSIS */
  41.     __AROS_LHA(struct Task *,     task, A1),
  42.  
  43. /*  LOCATION */
  44.     struct ExecBase *, SysBase, 48, Exec)
  45.  
  46. /*  FUNCTION
  47.     Remove a task from the task lists. All memory in the tc_MemEntry list
  48.     is freed and a rescedule is done. It's safe to call RemTask() out
  49.     of Forbid() or Disable().
  50.     This function is one way to get rid of the current task. The other way
  51.     is to fall through the end of the entry point.
  52.  
  53.     INPUTS
  54.     task - Task to be removed. NULL means current task.
  55.  
  56.     RESULT
  57.  
  58.     NOTES
  59.  
  60.     EXAMPLE
  61.  
  62.     BUGS
  63.  
  64.     SEE ALSO
  65.     AddTask()
  66.  
  67.     INTERNALS
  68.  
  69.     HISTORY
  70.  
  71. ******************************************************************************/
  72. {
  73.     __AROS_FUNC_INIT
  74.     struct MemList *mb;
  75.  
  76.     /* A value of NULL means current task */
  77.     if (task==NULL)
  78.     task=SysBase->ThisTask;
  79.  
  80.     D(bug("Call RemTask (%08lx (\"%s\"))\n", task, task->tc_Node.ln_Name));
  81.  
  82.     /*
  83.     Since it's possible that the following will free a task
  84.     structure that is used for some time afterwards it's
  85.     necessary to protect the free memory list so that nobody
  86.     can allocate that memory.
  87.     */
  88.     Forbid();
  89.  
  90.     /* Free all memory in the tc_MemEntry list. */
  91.     while((mb=(struct MemList *)RemHead(&task->tc_MemEntry))!=NULL)
  92.     /* Free one MemList node */
  93.     FreeEntry(mb);
  94.  
  95.     /* Changing the task lists always needs a Disable(). */
  96.     Disable();
  97.  
  98.     /* Freeing myself? */
  99.     if(task==SysBase->ThisTask)
  100.     {
  101.     /* Can't do that - let the dispatcher do it. */
  102.     task->tc_State=TS_REMOVED;
  103.  
  104.     /*
  105.         Since I don't know how many levels of Forbid()
  106.         are already pending I set a default value.
  107.     */
  108.     SysBase->TDNestCnt=-1;
  109.  
  110.     /* And force a task switch */
  111.     Switch();
  112.     /* Does not return. */
  113.     }else
  114.     /* Good luck. Freeing other tasks is simple. */
  115.     Remove(&task->tc_Node);
  116.  
  117.     /* All done. */
  118.     Enable();
  119.     Permit();
  120.  
  121.     ReturnVoid ("RemTask");
  122.     __AROS_FUNC_EXIT
  123. }
  124.  
  125.  
  126.